StringResource (Apache Ant API)

org.apache.tools.ant.types.resources

## Class StringResource

- java.lang.Object
- - org.apache.tools.ant.ProjectComponent
  - - org.apache.tools.ant.types.DataType
    - - org.apache.tools.ant.types.Resource
      - - org.apache.tools.ant.types.resources.StringResource

- All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<Resource>, java.lang.Iterable<Resource>, ResourceCollection

      public class StringResource
      extends Resource

  Exposes a string as a Resource.
  Since:
    Ant 1.7

- - ### Field Summary

    - ### Fields inherited from class org.apache.tools.ant.types.Resource

      `MAGIC, UNKNOWN_DATETIME, UNKNOWN_SIZE`

    - ### Fields inherited from class org.apache.tools.ant.types.DataType

      `checked, ref`

    - ### Fields inherited from class org.apache.tools.ant.ProjectComponent

      `description, location, project`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringResource()` Default constructor.
    `StringResource(Project project, java.lang.String value)` Construct a StringResource with the supplied project and value, doing property replacement against the project if non-null.
    `StringResource(java.lang.String value)` Construct a StringResource with the supplied value.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addText(java.lang.String text)` Add nested text to this resource.
    `protected java.lang.String` | `getContent()` Get the content of this StringResource.
    `java.lang.String` | `getEncoding()` Get the encoding used by this StringResource.
    `java.io.InputStream` | `getInputStream()` Get an InputStream for the Resource.
    `java.lang.String` | `getName()` Synchronize access.
    `java.io.OutputStream` | `getOutputStream()` Get an OutputStream for the Resource.
    `long` | `getSize()` Get the size of this Resource.
    `java.lang.String` | `getValue()` Get the value of this StringResource, resolving to the root reference if needed.
    `int` | `hashCode()` Get the hash code for this Resource.
    `boolean` | `isExists()` The exists attribute tells whether a resource exists.
    `void` | `setEncoding(java.lang.String s)` Set the encoding to be used for this StringResource.
    `void` | `setName(java.lang.String s)` Enforce String immutability.
    `void` | `setRefid(Reference r)` Overrides the super version.
    `void` | `setValue(java.lang.String s)` The value attribute is a semantically superior alias for the name attribute.
    `java.lang.String` | `toString()` Get the string.

    - ### Methods inherited from class org.apache.tools.ant.types.Resource

      `as, clone, compareTo, equals, getLastModified, getMagicNumber, isDirectory, isFilesystemOnly, iterator, setDirectory, setExists, setLastModified, setSize, size, toLongString`

    - ### Methods inherited from class org.apache.tools.ant.types.DataType

      `checkAttributesAllowed, checkChildrenAllowed, circularReference, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes`

    - ### Methods inherited from class org.apache.tools.ant.ProjectComponent

      `getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### StringResource

          public StringResource()

      Default constructor.

    - #### StringResource

          public StringResource(java.lang.String value)

      Construct a StringResource with the supplied value.
      Parameters:
        `value` - the value of this StringResource.

    - #### StringResource

          public StringResource(Project project,
                        java.lang.String value)

      Construct a StringResource with the supplied project and value, doing property replacement against the project if non-null.
      Parameters:
        `project` - the owning Project.
        `value` - the value of this StringResource.

  - ### Method Detail

    - #### setName

          public void setName(java.lang.String s)

      Enforce String immutability.
      Overrides:
        `setName` in class `Resource`
      Parameters:
        `s` - the new name/value for this StringResource.

    - #### setValue

          public void setValue(java.lang.String s)

      The value attribute is a semantically superior alias for the name attribute.
      Parameters:
        `s` - the String's value.

    - #### getName

          public java.lang.String getName()

      Synchronize access.
      Overrides:
        `getName` in class `Resource`
      Returns:
        the name/value of this StringResource.

    - #### getValue

          public java.lang.String getValue()

      Get the value of this StringResource, resolving to the root reference if needed.
      Returns:
        the represented String.

    - #### isExists

          public boolean isExists()

      The exists attribute tells whether a resource exists.
      Overrides:
        `isExists` in class `Resource`
      Returns:
        true if this resource exists.

    - #### addText

          public void addText(java.lang.String text)

      Add nested text to this resource. Properties will be expanded during this process.
      Parameters:
        `text` - text to use as the string resource
      Since:
        Ant 1.7.1

    - #### setEncoding

          public void setEncoding(java.lang.String s)

      Set the encoding to be used for this StringResource.
      Parameters:
        `s` - the encoding name.

    - #### getEncoding

          public java.lang.String getEncoding()

      Get the encoding used by this StringResource.
      Returns:
        the encoding name.

    - #### getSize

          public long getSize()

      Get the size of this Resource.
      Overrides:
        `getSize` in class `Resource`
      Returns:
        the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.

    - #### hashCode

          public int hashCode()

      Get the hash code for this Resource.
      Overrides:
        `hashCode` in class `Resource`
      Returns:
        hash code as int.

    - #### toString

          public java.lang.String toString()

      Get the string. See `getContent()`
      Overrides:
        `toString` in class `Resource`
      Returns:
        the string contents of the resource.
      Since:
        Ant 1.7

    - #### getInputStream

          public java.io.InputStream getInputStream()
                                             throws java.io.IOException

      Get an InputStream for the Resource.
      Overrides:
        `getInputStream` in class `Resource`
      Returns:
        an InputStream containing this Resource's content.
      Throws:
        `java.io.IOException` - if unable to provide the content of this Resource as a stream.
        `java.lang.UnsupportedOperationException` - if InputStreams are not supported for this Resource type.

    - #### getOutputStream

          public java.io.OutputStream getOutputStream()
                                               throws java.io.IOException

      Get an OutputStream for the Resource.
      Overrides:
        `getOutputStream` in class `Resource`
      Returns:
        an OutputStream to which content can be written.
      Throws:
        `java.io.IOException` - if unable to provide the content of this Resource as a stream.
        `java.lang.UnsupportedOperationException` - if OutputStreams are not supported for this Resource type.

    - #### setRefid

          public void setRefid(Reference r)

      Overrides the super version.
      Overrides:
        `setRefid` in class `Resource`
      Parameters:
        `r` - the Reference to set.

    - #### getContent

          protected java.lang.String getContent()

      Get the content of this StringResource. See `getValue()`
      Returns:
        a String or null if there is no value.